/**
 * Created by Administrator on 2015/12/29.
 */
angular.module('ddfd.service',[])
  .service('ddfdService',['$http','$localstorage','$timeout','appItfAopService',function($http,$localstorage,$timeout,appItfAopService){
    var params={
      "mac":"",
      //"MobilePhone":"13296600614",//手机号码,
      //"searchUserInfoByPhone":{"mobilePhone": "13296600614"},
      "MobilePhone":"",//手机号码,
      "searchUserInfoByPhone":{"mobilePhone": ""},
      "ICCIDNum":"",//SIM卡号（ICCID）
      "QueryUserBySimParams":{
          "QryType":"",  //查询类别，1- 根据SIM查号码，2 - 根据号码查SIM，必填
          "QryCode":"", //查询类别为SIM时，该参数为号码，查询类别为号码时，该参数为SIM，必填
          "IsPre":"0", //是否为预配号码。0已开卡（返档使用）；1预配卡（开卡使用），必填
         },
      "BlueSimCard":{},
      "BarSimCard":{"text":""},
      "IdCard":{"address":""},
      "ValidMobilePhoneData4G":{},
      "ValidMobilePhoneData2G":{},
      "userDataReturnOk2G":{
        "StatusChgTime":"",
        "ReleOfficeID":"",
        "OrgType":"",
        "OrgLeagalRep":"",
        "OrgID":"",
        "NativePlace":"",
        "MaritalStatus":"",
        "IndividualBrandID":"",
        "Hobby":"",
        "DevChnlID":"",
        "DefaultLan":"",
        "CustStatus":"",
        "CustomerZip":"",
        "CustomerType":"",
        "CustomerSex":"",
        "CustomerOrga":"",
        "CustomerOccp":"",
        "userName":"",
        "CustomerLoc":"",
        "CustomerID":"",
        "CustomerEmail":"",
        "CustomerBirth":"",
        "CustomerAddr":"",
        "CustLoc":"",
        "CorpBrandID":"",
        "ContactZip":"",
        "ContactPhone":"",
        "ContactPerson":"",
        "ContactEmail":"",
        "ContactAddr":"",
        "CertType":"",
        "IdNum":"",
        "CertExpireDate":"",
        "userAddress":"",
        "MobilePhone":""
      },
      "userDataReturnOk4G":{
          "BASIC_CREDIT_VALUE": "", //查询返回
          "CREDIT_CLASS": "-1", //查询返回
          "CUST_STATE": "0",  //查询返回
          "CUST_ID": "",  //查询返回
          "OPEN_LIMIT": "0",//查询返回
          "CUST_NAME": "夏利辉",                        //从二代证读取
          "PSPT_TYPE_CODE": "1", //查询返回
          "PSPT_ID": "341224198809170256",              //从二代证读取出来的证件号码
          "SEX": "0",//二代证
          "PSPT_END_DATE": "2022-01-11",//二代证
          "PSPT_ADDR": "安徽省合肥市蜀山区莲花路１６８８号合肥师范学院１０级计算机系", //二代证
          "HOME_ADDRESS": "",//查询返回
          "PHONE": "18795959195",//查询返回
          "POST_ADDRESS": "安徽省合肥市蜀山区莲花路１６８８号合肥师范学院１０级计算机系",//查询返回
          "POST_CODE": "",//查询返回
          "CONTACT": "夏利辉",//查询返回
          "CONTACT_PHONE": "18795959195",//查询返回
          "CONTACT_TYPE_CODE": "",//查询返回
          "WORK_NAME": "",//查询返回
          "WORK_PHONE": "",//查询返回
          "WORK_ADDRESS": "",//查询返回
          "JOB_TYPE_CODE": "",//查询返回
          "JOB": "",//查询返回
          "EMAIL": "",//查询返回
          "FAX_NBR": "",//查询返回
          "CUST_TAG": "",//查询返回
          "TRADE_ID": "7116011556438738",//           从返回TRADEID字段取值
          "ORDER_TYPE": "0",//查询返回
          "X_TAG": "2",//固定写死
          "USER_ID": "7116011567200534",//查询返回
          "SERIAL_NUMBER_NO": "13296600248",//返档查询接口使用的手机号
          "ACCT_ID": "7116011511732696",//查询返回
          "ACCEPT_DATE": "2016-01-15 09:21:34",//查询返回
          "TRADE_CITY_CODE": "71a0a1",//查询返回
          "CITY_CODE": "71a0a1",//查询返回
          "NET_TYPE_CODE": "",//固定写死传“”
          "CANCEL_TAG": "0",//查询返回
          "IN_MODE_CODE": "0",//查询返回
          "PRODUCT_ID": "89013015",//查询返回
          "BRAND_CODE": "4G00",//查询返回brandCodeForTrade
          "GROUPMARK": "",//查询返回
          "CUST_ID_FOR_GROUP": "7116011512000639",//查询返回
          "MobilePhone":""
      },
      "insertPsptInfo":{
          "Name": "",//夏利辉
          "Sex": "",//1
          "Nation": "",//汉
          "CheckType": "1",
          "folkCode": "",
          "Born": "",//1988-09-17
          "Address": "",//安徽省合肥市蜀山区莲花路１６８８号合肥师范学院１０级计算机系
          "CardNo": "",//341224198809170256
          "Police": "",//合肥市公安局蜀山分局
          "ActivityLFrom": "",//20120111
          "ActivityLTo": "",//20220111
          "CardReaderId": "0000845838",
          //"PhotoBuffer":"/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAB+AGYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD36iiigAoqpqWp2mkWMl3eTLFCg5LHr7CvCPGfx2upQ9n4fiEC5w1w3LfQDp+NAHuepa5pekWz3GoX9vbxJ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QQc10pp7HG01uPooopiPOTqM93Iy3Um6U9cnj8KoTQvA7DHynpVi4tIwBPzvU8EHFW7cC4iO8ZBolG6JhUcZGDJgmnwKuRWrcaZCVLL8v0FZxhEJwprlnBo74VIyL1uoDY7GrvkgnNZMUzKw5zWjHO22smdCfQmMdQyqORTzKxNUbq4dCcUIpkU8YIIqjsCGpjcPIeTV620sTBZJJCQwyBVRjdmE58urK0CeeRGASCOeK3UuXsMeS7Kw4AFILaO3ixGMYqoczXGSSCOMiuyELLU8+rV5nodNY+IG8oC8TLY6xj+lFc7IXibb5hNFXYy5mf/9k="
          "PhotoBuffer":""
      },
      "tijiao":0
    }


    return{
      getParams:function() {
        return params;
      },


      ReadIccid:function(param){
        //ios插件真心无语,必须要先去搜索,然后匹配,然后读卡,每次操作都要这样
        /*设备列表刷新*/
        var options = {};
        options.deviceType = ['2', '4', '8'];
        options.name=param;
        console.log('设备列表扫描:' + JSON.stringify(options));

        $ionicLoading.show({
          template: '<ion-spinner icon="ios"></ion-spinner>',
          content: '拼命加载中，请耐心等候...',
          animation: 'fade-in',
          showBackdrop: false,
          maxWidth: 200,
          showDelay: 0
        });

        //搜索蓝牙设备,可以直接调用搜索的就可以,
        BLEIDCardPlugin.ai_refreshDeviceList(function (result) {
          console.log('扫描到的设备列表如下:' + JSON.stringify(result) + '设备个数:' + result.devices.length);
          $timeout(function(){
          },1000);
        }, function (error) {
          console.error('设备扫描失败' + JSON.stringify(error));
          $ionicLoading.hide();
        }, JSON.stringify(options));

        //匹配蓝牙设备
        BLEIDCardPlugin.ai_connectDevice(function (result) {
          console.log('读卡器连接成功');
          console.log('混合界面开始读取ICCID:' + JSON.stringify(options));
          BLEIDCardPlugin.ai_readICCID(function (result) {
            console.log('读取到的ICCID信息如下:' + JSON.stringify(result));
            params.BlueSimCard=angular.fromJson(success);
            console.log("==========Service===============");
            console.log(params.BlueSimCard);
            $ionicLoading.hide();
          }, function (error) {
            console.log('读取ICCID信息失败:' + JSON.stringify(error));
            $ionicLoading.hide();
          }, JSON.stringify(options));

        }, function (error) {
          console.log('读卡器连接失败');
          $ionicLoading.hide();
        }, JSON.stringify(options));

      },



     readIdCard:function(param){
//ios插件真心无语,必须要先去搜索,然后匹配,然后读卡,每次操作都要这样
       /*设备列表刷新*/
       var options = {};
       options.deviceType = ['2', '4', '8'];
       options.name=param;
       console.log('设备列表扫描:' + JSON.stringify(options));

       $ionicLoading.show({
         template: '<ion-spinner icon="ios"></ion-spinner>',
         content: '拼命加载中，请耐心等候...',
         animation: 'fade-in',
         showBackdrop: false,
         maxWidth: 200,
         showDelay: 0
       });

       //搜索蓝牙设备,可以直接调用搜索的就可以,
       BLEIDCardPlugin.ai_refreshDeviceList(function (result) {
         console.log('扫描到的设备列表如下:' + JSON.stringify(result) + '设备个数:' + result.devices.length);
         $timeout(function(){
         },1000);
       }, function (error) {
         console.error('设备扫描失败' + JSON.stringify(error));
         $ionicLoading.hide();
       }, JSON.stringify(options));

       //匹配蓝牙设备
       BLEIDCardPlugin.ai_connectDevice(function (result) {
         console.log('读卡器连接成功');
         console.log('混合界面开始读取证件:' + JSON.stringify(options));
         BLEIDCardPlugin.ai_readIDCard(function (result) {
           console.log('读取到的证件信息如下:' + JSON.stringify(result));
           params.tijiao=1;//下一步按钮可用
           //params.IdCard=result;

           //在这里将数据封装成森锐的数据 不用大面积更改开户使用的原森锐参数
           params.IdCard.address=result.Address;
           params.IdCard.authority=result.IssuedAt;
           params.IdCard.avatar=result.Avatar;
           params.IdCard.birth=result.Birth;
           params.IdCard.cardNo=result.CardNo;
           params.IdCard.ethnicity=result.Nation;
           params.IdCard.name=result.Name;
           params.IdCard.period=result.EffectedDate+"-"+result.ExpiredDate;
           params.IdCard.sex=result.Sex;

           console.log(angular.toJson(params.IdCard.Address));
           $ionicLoading.hide();
         }, function (error) {
           console.log('读取证件信息失败:' + JSON.stringify(error));
           $ionicLoading.hide();
           params.tijiao=0;//下一步按钮禁用
         }, JSON.stringify(options));

       }, function (error) {
         console.log('读卡器连接失败');
         $ionicLoading.hide();
       }, JSON.stringify(options));
      },


      //校验手机号是否可以返档
      validMobilePhone:function(params)
      {
        return appItfAopService.do_searchUserInfoByPhone_req(params);
      },

      //手机号和SIM卡号互查
      queryUserBySim:function(params)
      {
        return appItfAopService.do_queryUserBySim_req(params);
      },
      //4G确认返档
      userDataReturnOk4G:function(params)
      {
        return appItfAopService.do_userDataReturnOk4G_rep(params);
      },
      //2G确认返档
      userDataReturnOk2G:function(params)
      {
        return appItfAopService.do_userDataReturnOk2G_rep(params);
      },
      //4G返档特有接口需要插入身份证信息
      insertPsptInfo:function(params)
      {
        return appItfAopService.do_insertPsptInfo_req(params);
      },
      //插入日志
      insertLog:function(param)
      {
        return appItfAopService.do_insertLog_req(param);
      }
    }
  }]);
